package com.drojian.demo1.myself;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.drojian.demo.R;

public class MyView5 extends View {
    public MyView5(Context context) {
        super(context);
    }

    public MyView5(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView5(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        Paint paint = new Paint();
        Path path = new Path();
        //绘制坐标轴
        paint.reset();//清除所有属性
        path.reset();//清除所有属性
        paint.setStyle(Paint.Style.STROKE);
        path.moveTo(100,100);//原点坐标
        path.rLineTo(0,402);//原点向下移动402dp(0为竖线)
        path.rLineTo(800,0);//x轴方向的长度(0为直线)
        paint.setStrokeWidth(4);//坐标轴的宽度
        canvas.drawPath(path,paint);
        //绘制文字
        paint.reset();
        paint.setTextSize(30);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawText("一月",165,540,paint);
        canvas.drawText("二月",270,540,paint);
        canvas.drawText("三月",370,540,paint);
        canvas.drawText("四月",470,540,paint);
        canvas.drawText("五月",570,540,paint);
        canvas.drawText("六月",670,540,paint);
        canvas.drawText("七月",770,540,paint);
        //设置颜色
        paint.setColor(Color.rgb(0,180,255));
        paint.setStrokeWidth(60);//柱的宽度
        //起点的X坐标、起点的Y坐标、终点的X坐标、终点的Y坐标
        float[] line = {200,500,200,460,
                        300,500,300,480,
                        400,500,400,480,
                        500,500,500,300,
                        600,500,600,200,
                        700,500,700,150,
                        800,500,800,350,};
        canvas.drawLines(line,paint);
        super.onDraw(canvas);
    }
}
